#include "../../head.h"

int main()
{
    if (access("/home/jinyu/read", R_OK) == -1 && access("/home/jinyu/write", W_OK) == -1)
    {
        mkfifo("/home/jinyu/read", 0777);
        mkfifo("/home/jinyu/write", 0777);
    }
    else
    {
        printf("文件已存在\n");
    }
    int fd = open("/home/jinyu/write", O_RDONLY);
    int fp = open("/home/jinyu/read", O_WRONLY);  
    
    pid_t pid = fork();

    if (pid == 0)
    {
        char output[32];
        while (1)
        {
            read(fd, output, sizeof(output));
            if (strcmp(output, "exit") == 0)
            {
                break;
            }
            printf("%s\n", output);
        }
    }
    if (pid > 0)
    {
        char input[32];
        while (1)
        {
            scanf("%s", input);
            write(fp, input, sizeof(input));
            if (strcmp(input, "exit") == 0)
            {
                break;
            }  
        }
        wait(NULL);
    }
    



}